/*
 * Copyright (c) 2013. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.jspx.txweb.view;

import com.jspx.boot.environment.Environment;
import com.jspx.sioc.annotation.Ref;
import com.jspx.txweb.annotation.HttpMethod;
import com.jspx.txweb.annotation.Safety;
import com.jspx.txweb.annotation.TurnPage;
import com.jspx.txweb.dao.ActionLogDAO;
import com.jspx.txweb.support.ActionSupport;
import com.jspx.utils.ArrayUtil;
import com.jspx.utils.StringUtil;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: yuan
 * Date: 13-10-16
 * Time: 下午10:11
 */
@HttpMethod(caption = "日志")
public class ActionLogView extends ActionSupport {

    public ActionLogView() {

    }

    protected ActionLogDAO actionLogDAO;
    @Ref(name = Environment.actionLogDAO)
    public void setActionLogDAO(ActionLogDAO actionLogDAO) {
        this.actionLogDAO = actionLogDAO;
    }


    private String turnPage = StringUtil.empty;
    private int count = 0;
    private long uid = 0;
    private int currentPage = 0;
    private String term = StringUtil.empty;
    private String sort = "createDate:D";
    private String[] field = ArrayUtil.emptyString;
    private String[] find = ArrayUtil.emptyString;
    private long id;

    @Safety(request = false)
    @TurnPage(params = "find;field;sort;uid")
    public void setTurnPage(String turnPage) {
        this.turnPage = turnPage;
    }

    public String getTurnPage() {
        return turnPage;
    }

    public String[] getField() {
        return field;
    }

    @Safety
    public void setField(String[] field) {
        this.field = field;
    }

    public String[] getFind() {
        return find;
    }

    @Safety
    public void setFind(String[] find) {
        this.find = find;
    }

    public String getTerm() {
        return term;
    }

    @Safety
    public void setTerm(String term) {
        this.term = term;
    }

    public String getSort() {
        return sort;
    }

    @Safety
    public void setSort(String sort) {
        this.sort = sort;
    }

    public long getUid() {
        return uid;
    }

    public void setUid(long uid) {
        this.uid = uid;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getCount() {
        if (count <= 0) {
            count = 12;
        }
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @SuppressWarnings("unchecked")
    public List getList() throws Exception {
        return actionLogDAO.getList(field, find, getTerm(), sort, getUid(), getCurrentPage(), getCount());
    }

    public int getTotalCount() throws Exception {
        return actionLogDAO.getCount(field, find, term, getUid());
    }

    public String execute() throws Exception {
        put("actionLog", actionLogDAO.load(id));
        return getActionResult();
    }
}